package com.zoweunion.mechanic.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * 管辖区域redis缓存工具
 */
@Component
public class ServerAreaRegionRedisUtil {

    public static final String KEY_PREFIX_MECHANIC_PLATFORM = "mechanic";
    public static final String KEY_PREFIX_ALL_ADDRESS_LIST = ":allAddressList";
    public static final String KEY_PREFIX_SERVER_ADDRESS_LIST = ":allServerAddressList";
    public static final String KEY_ALL_ADDRESS_LIST = KEY_PREFIX_MECHANIC_PLATFORM + KEY_PREFIX_ALL_ADDRESS_LIST;
    public static final String KEY_ALL_SERVER_ADDRESS_LIST = KEY_PREFIX_MECHANIC_PLATFORM + KEY_PREFIX_SERVER_ADDRESS_LIST;

    @Autowired
    RedisTemplate redisTemplate;

    public void setAddressList(Object obj) {
        redisTemplate.opsForValue().set(KEY_ALL_ADDRESS_LIST, obj);

    }

    public Object getAddressList() {
        return redisTemplate.opsForValue().get(KEY_ALL_ADDRESS_LIST);
    }

    public boolean deleteAddressList() {
        return redisTemplate.delete(KEY_ALL_ADDRESS_LIST);
    }

    public void setAddressListWithSuffix(String keySuffix, Object obj) {
        redisTemplate.opsForValue().set(KEY_ALL_SERVER_ADDRESS_LIST + ":" + keySuffix , obj);

    }

    public Object getAddressListWithSuffix(String keySuffix) {
        return redisTemplate.opsForValue().get(KEY_ALL_SERVER_ADDRESS_LIST + ":" + keySuffix);
    }

    public boolean deleteAddressListWithSuffix(String keySuffix) {
        return redisTemplate.delete(KEY_ALL_SERVER_ADDRESS_LIST + ":" + keySuffix);
    }
}
